Extension = sgs.Package("K",sgs.Package_GeneralPack)

sgs.LoadTranslationTable{
    ["K"] = "克",
}

do
    require "lua.config" 
    local config = config
    local kingdoms = config.kingdoms
       table.insert(kingdoms,"hj")
   config.color_de = "#EDB71F"
end

sgs.LoadTranslationTable{
    ["hj"] = "黄巾",
}

K_chengyuanzhi = sgs.General(Extension,"K_chengyuanzhi","hj",4,true,false,false)

sgs.LoadTranslationTable{
    ["K_chengyuanzhi"] = "克·程远志",
    ["&K_chengyuanzhi"] = "程远志",
    ["#K_chengyuanzhi"] = "刀下亡魂",
    ["designer:K_chengyuanzhi"] = "Crashock"
}

S_shouzhanCard = sgs.CreateSkillCard{
    name = "S_shouzhanCard",
    filter = function(self, targets, to_select)
        local targets_list = sgs.PlayerList()
		for _, target in ipairs(targets) do
			targets_list:append(target)
		end
        local duel = sgs.Sanguosha:cloneCard("duel", sgs.Card_NoSuit, 0)
        duel:setSkillName(self:objectName())
		duel:deleteLater()
		return duel:targetFilter(targets_list, to_select, sgs.Self)
    end,
    on_use = function(self, room, source, targets)
        local targets_list = sgs.SPlayerList()
        local duel = sgs.Sanguosha:cloneCard("duel", sgs.Card_NoSuit, 0)
        for _, target in ipairs(targets) do
            if not source:isProhibited(target,duel) then
                targets_list:append(target)
            end
        end
        if targets_list:length() > 0 then
            duel:setSkillName("S_shouzhan")
            room:useCard(sgs.CardUseStruct(duel, source, targets_list))
        end
    end
}

S_shouzhanVS = sgs.CreateZeroCardViewAsSkill{
    name = "S_shouzhan",
    response_pattern = "@@S_shouzhan",
    view_as = function() 
        return S_shouzhanCard:clone()
    end,
    enabled_at_play = function()
        return false
    end,
    enabled_at_response = function(self, player, pattern)
        return string.startsWith(pattern, "@@S_shouzhan")
    end
}

S_shouzhan = sgs.CreateTriggerSkill{
    name = "S_shouzhan",
    frequency = sgs.Skill_NotFrequent,
    view_as_skill = S_shouzhanVS,
    priority = 0,
    events = {sgs.RoundStart},
    on_trigger = function(self,event,player,data,room)
        room:askForUseCard(player, "@@S_shouzhan", "@shouzhan-card")
    end
}

K_chengyuanzhi:addSkill(S_shouzhan)

sgs.LoadTranslationTable{
    ["S_shouzhan"] = "首战",
    [":S_shouzhan"] = "每轮开始时，你可以视为使用一张【决斗】。",
    ["@shouzhan-card"] = "你可以发动“首战”视为使用【决斗】 操作提示：选择【决斗】的目标→点“确定”"
}

K_lingcao = sgs.General(Extension,"K_lingcao","wu",4,true,false,false)

sgs.LoadTranslationTable{
    ["K_lingcao"] = "克·凌操",
    ["&K_lingcao"] = "凌操",
    ["#K_lingcao"] = "激流勇进",
    ["designer:K_lingcao"] = "Crashock"
}

S_dujinCard = sgs.CreateSkillCard{
    name = "S_dujinCard",
    target_fixed = true,
    mute = true,
    on_use = function(self, room, source, targets)
        if source:isAlive() and source:hasEquip() then
            source:throwAllEquips()
            room:drawCards(source, 2, "dujin")
        end
    end
}

S_dujin = sgs.CreateZeroCardViewAsSkill{
    name = "S_dujin",
    view_as = function(self)
        local dujin_card = S_dujinCard:clone()
        dujin_card:setSkillName(self:objectName())
        return dujin_card
    end,
    enabled_at_play = function(self,player)
        return not player:hasUsed("#S_dujinCard") and player:canDiscard(player, "e")
    end,
    enabled_at_response = function(self, target, pattern)
        return pattern == "@dujin"
    end
}

K_lingcao:addSkill(S_dujin)

sgs.LoadTranslationTable{
    ["S_dujin"] = "独进",
    ["s_dujin"] = "独进",
    [":S_dujin"] = "出牌阶段限一次，你可以弃置装备区里的牌（至少一张），摸两张牌。"
}

K_chiyou = sgs.General(Extension,"K_chiyou","god",4,true,false,false)

sgs.LoadTranslationTable{
    ["K_chiyou"] = "克·蚩尤",
    ["&K_chiyou"] = "蚩尤",
}

S_huibing = sgs.CreateTriggerSkill{
    name = "S_huibing",
    frequency = sgs.Skill_NotFrequent,
    events = {sgs.CardUsed,sgs.CardResponded},
    on_trigger = function (self,event,player,data,room)
        local equips = player:getEquips()
        local card = nil
        if event == sgs.CardUsed then
            local use = data:toCardUse()
            card = use.card
        else
            local respond = data:toCardResponse()
            card = respond.m_card
        end
        for _, equip in sgs.qlist(equips) do
            if equip:CompareBySuit(equip,card) then
                player:drawCards(1)
                break
            end
        end
    end
}

K_chiyou:addSkill(S_huibing)

return {Extension}